
/* ----------------------------------------------------------------------
*
* Copyright (C) 2025 XiaoFei. All rights reserved.
*
* $file:        XiaoFei_CRC.h
* $Date:        09-August-2025
* $Revision:    V1
* $Project:     XiaoFei BSP Library
*
* -------------------------------------------------------------------- */

#ifndef __XiaoFei_CRC_H
#define __XiaoFei_CRC_H

#define CRC_Rcc(x)                      RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, (FunctionalState)x)

#ifndef CRC32_Typedef_def
#define CRC32_Typedef_def
typedef struct
{
    unsigned int ploy;	        /*!< The CRC32 ploy data for init */
    unsigned int init;	        /*!< The CRC32 init data for init */
    unsigned int temp;	        /*!< The CRC32 temp data for continuous calculations */
    unsigned char invin;	    /*!< The data is 0x00 if the input data is not inverted */
    unsigned char invout;	    /*!< The data is 0x00 if the output data is not inverted */
}CRC32_Typedef;
#endif

#ifndef CRC16_Typedef_def
#define CRC16_Typedef_def
typedef struct
{
	unsigned short int ploy;	/*!< The CRC16 ploy data for init */
	unsigned short int init;	/*!< The CRC16 init data for init */
	unsigned short int temp;    /*!< The CRC16 temp data for continuous calculations */
	unsigned char invin;	    /*!< The data is 0x00 if the input data is not inverted */
	unsigned char invout;	    /*!< The data is 0x00 if the output data is not inverted */
}CRC16_Typedef;
#endif

#ifndef CRC8_Typedef_def
#define CRC8_Typedef_def
typedef struct
{
	unsigned char ploy;         /*!< The CRC8 ploy data for init */
	unsigned char init;         /*!< The CRC8 init data for init */
	unsigned char temp;         /*!< The CRC8 temp data for continuous calculations */
	unsigned char invin;	    /*!< The data is 0x00 if the input data is not inverted */
	unsigned char invout;	    /*!< The data is 0x00 if the output data is not inverted */
}CRC8_Typedef;
#endif

/* 
* @function: 	CRC_Get
* @parameter:	[in] Buffer				    The first address of the data that will be computed.
* @parameter:	[in] Length				    The length of the data that will be computed.
* @parameter:	[in] isReset				Write 0x00 if you want to reset the CRC calculation before calculating.
* @return:		The result of the CRC operation.
*/
unsigned int CRC_Get(unsigned int* Buffer, unsigned int Length, unsigned char isReset);

/* 
* @function: 	My_Inv8
* @parameter:	[in] data				    The original data that will be used as a bit inversion operation.
* @return:		Calculation results after bit inversion.
*/
unsigned char My_Inv8(unsigned char data);

/* 
* @function: 	My_Inv16
* @parameter:	[in] data				    The original data that will be used as a bit inversion operation.
* @return:		Calculation results after bit inversion.
*/
unsigned short int My_Inv16(unsigned short int data);

/* 
* @function: 	My_Inv32
* @parameter:	[in] data				    The original data that will be used as a bit inversion operation.
* @return:		Calculation results after bit inversion.
*/
unsigned int My_Inv32(unsigned int data);

/* 
* @function: 	My_CRC32
* @parameter:	[in] data				    The first address of the data that will be computed.
* @parameter:	[in] Length				    The length of the data that will be computed.
* @parameter:	[in] CRC32				    Detailed parameters for the CRC32 operation you need.
* @parameter:	[in] isReset				Write 0x00 if you want to reset the CRC calculation before calculating.
* @return:		The result of the CRC32 operation.
*/
unsigned int My_CRC32(unsigned char* data, unsigned int Length, CRC32_Typedef* CRC32, unsigned char isReset);

/* 
* @function: 	My_CRC16
* @parameter:	[in] data				    The first address of the data that will be computed.
* @parameter:	[in] Length				    The length of the data that will be computed.
* @parameter:	[in] CRC16				    Detailed parameters for the CRC16 operation you need.
* @parameter:	[in] isReset				Write 0x00 if you want to reset the CRC calculation before calculating.
* @return:		The result of the CRC16 operation.
*/
unsigned short int My_CRC16(unsigned char* data, unsigned int Length, CRC16_Typedef* CRC16, unsigned char isReset);

/* 
* @function: 	My_CRC8
* @parameter:	[in] data				    The first address of the data that will be computed.
* @parameter:	[in] Length				    The length of the data that will be computed.
* @parameter:	[in] CRC8				    Detailed parameters for the CRC8 operation you need.
* @parameter:	[in] isReset				Write 0x00 if you want to reset the CRC calculation before calculating.
* @return:		The result of the CRC8 operation.
*/
unsigned char My_CRC8(unsigned char* data, unsigned int Length, CRC8_Typedef* CRC8, unsigned char isReset);

#endif

